<template>
  <div class="person">
    <h2>一辆{{ brand }}车，价值{{ price }}万</h2>
    <button @click="changeName">修改名称</button>
    <button @click="changePrice">修改价格</button>
    <button @click="changeJiage">单独修改价格</button>
  </div>
</template>

<script lang="ts" setup name="Person">
import { ref, reactive, toRefs, toRef } from 'vue'

let car = reactive({ brand: '奔驰', price: 10 })

let { brand, price } = toRefs(car);

let jiage = toRef(car, 'price');

console.log(car)


function changeName() {
  brand.value = '大众'
  console.log(brand)
}

function changePrice() {
  price.value += 10
  console.log(price)
}

function changeJiage() {
  jiage.value += 50
  console.log(jiage)
}


function changeCar() {
  car = { brand: '奥迪', price: 20 }
}

</script>

<style scoped>
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}

button {
  margin: 0 5px;
}
</style>